import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';

/**
 * @Description: url跳转工具类  使用示范
 * @Author: 下雨了
 * @CreateDate: 2022-01-20 15:47
 * @UpdateUser: 更新者
 * @UpdateDate:  2022-01-20 15:47
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
///
//
// dependencies:
//   url_launcher: ^6.0.18
//
class UrlLauncherUtils {
  //私有构造函数
  UrlLauncherUtils._internal();

  //保存单例
  static final UrlLauncherUtils _launcherUtils = UrlLauncherUtils._internal();

  //工厂构造函数
  factory UrlLauncherUtils() => _launcherUtils;

  /// Parses the specified URL string and delegates handling of it to the underlying platform.
  Future<bool> launchs(String url) async {
    if (url.isNotEmpty) {
      return await launchUrlString(url, mode: LaunchMode.externalApplication);
    }
    return false;
  }

  /// Checks whether the specified URL can be handled by some app installed on the device.
  Future<bool> canLaunchs(String url) async {
    if (url.isNotEmpty) {
      return await canLaunchUrlString(url);
    }
    return false;
  }

  ///  Closes the current in-app web view, if one was previously opened by [launchUrl].
  Future<void> closeWebViews() async {
    return await closeInAppWebView();
  }
}
